﻿using System;
using System.Diagnostics;
using System.IO;

namespace Ndns.Packet.Abstractions
{
    public class PacketEndOfStreamException : EndOfStreamException
    {
        public PacketEndOfStreamException() { }

        public PacketEndOfStreamException(string message) : base(message) { }

        public PacketEndOfStreamException(string message, Exception inner) : base(message, inner) { }


        public static bool CheckValue(long value)
        {
            return value != -1;
        }
        public static bool CheckValue(int value)
        {
            return value != -1;
        }
        public static bool CheckValue(params int[] values)
        {
            Debug.Assert(values != null);

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] == -1)
                    return false;
            }
            return true;
        }
        public static bool CheckValue(params long[] values)
        {
            Debug.Assert(values != null);

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] == -1)
                    return false;
            }
            return true;
        }



        public static void CheckAndThrow(long value)
        {
            if (value == -1)
                throw new EndOfStreamException();
        }
        public static void CheckAndThrow(int value)
        {
            if (value == -1)
                throw new EndOfStreamException();
        }
        public static void CheckAndThrow(params int[] values)
        {
            Debug.Assert(values != null);

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] == -1)
                    throw new EndOfStreamException();
            }

        }
        public static void CheckAndThrow(params long[] values)
        {
            Debug.Assert(values != null);

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] == -1)
                    throw new EndOfStreamException();
            }
        }
    }
}
